﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwIspisProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwIspisProviderBaseCore : EntityViewProviderBase<VwIspis>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwIspis&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwIspis&gt;"/></returns>
		protected static VList&lt;VwIspis&gt; Fill(DataSet dataSet, VList<VwIspis> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwIspis>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwIspis&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwIspis>"/></returns>
		protected static VList&lt;VwIspis&gt; Fill(DataTable dataTable, VList<VwIspis> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwIspis c = new VwIspis();
					c.IspisID = (Convert.IsDBNull(row["IspisID"]))?(int)0:(System.Int32)row["IspisID"];
					c.IspisNaziv = (Convert.IsDBNull(row["IspisNaziv"]))?string.Empty:(System.String)row["IspisNaziv"];
					c.IspisKolonaID = (Convert.IsDBNull(row["IspisKolonaID"]))?(int)0:(System.Int32)row["IspisKolonaID"];
					c.IspisKolonaNaziv = (Convert.IsDBNull(row["IspisKolonaNaziv"]))?string.Empty:(System.String)row["IspisKolonaNaziv"];
					c.IspisKolonaNaziv2 = (Convert.IsDBNull(row["IspisKolonaNaziv2"]))?string.Empty:(System.String)row["IspisKolonaNaziv2"];
					c.TipIspisaID = (Convert.IsDBNull(row["TipIspisaID"]))?(int)0:(System.Int32)row["TipIspisaID"];
					c.TipIspisaNaziv = (Convert.IsDBNull(row["TipIspisaNaziv"]))?string.Empty:(System.String)row["TipIspisaNaziv"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwIspis&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwIspis&gt;"/></returns>
		protected VList<VwIspis> Fill(IDataReader reader, VList<VwIspis> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwIspis entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwIspis>("VwIspis",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwIspis();
					}
					entity.IspisID = (System.Int32)reader["IspisID"];
					//entity.IspisID = (Convert.IsDBNull(reader["IspisID"]))?(int)0:(System.Int32)reader["IspisID"];
					entity.IspisNaziv = (System.String)reader["IspisNaziv"];
					//entity.IspisNaziv = (Convert.IsDBNull(reader["IspisNaziv"]))?string.Empty:(System.String)reader["IspisNaziv"];
					entity.IspisKolonaID = (System.Int32)reader["IspisKolonaID"];
					//entity.IspisKolonaID = (Convert.IsDBNull(reader["IspisKolonaID"]))?(int)0:(System.Int32)reader["IspisKolonaID"];
					entity.IspisKolonaNaziv = (System.String)reader["IspisKolonaNaziv"];
					//entity.IspisKolonaNaziv = (Convert.IsDBNull(reader["IspisKolonaNaziv"]))?string.Empty:(System.String)reader["IspisKolonaNaziv"];
					entity.IspisKolonaNaziv2 = reader.IsDBNull(reader.GetOrdinal("IspisKolonaNaziv2")) ? null : (System.String)reader["IspisKolonaNaziv2"];
					//entity.IspisKolonaNaziv2 = (Convert.IsDBNull(reader["IspisKolonaNaziv2"]))?string.Empty:(System.String)reader["IspisKolonaNaziv2"];
					entity.TipIspisaID = (System.Int32)reader["TipIspisaID"];
					//entity.TipIspisaID = (Convert.IsDBNull(reader["TipIspisaID"]))?(int)0:(System.Int32)reader["TipIspisaID"];
					entity.TipIspisaNaziv = (System.String)reader["TipIspisaNaziv"];
					//entity.TipIspisaNaziv = (Convert.IsDBNull(reader["TipIspisaNaziv"]))?string.Empty:(System.String)reader["TipIspisaNaziv"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwIspis"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwIspis"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwIspis entity)
		{
			reader.Read();
			entity.IspisID = (System.Int32)reader["IspisID"];
			//entity.IspisID = (Convert.IsDBNull(reader["IspisID"]))?(int)0:(System.Int32)reader["IspisID"];
			entity.IspisNaziv = (System.String)reader["IspisNaziv"];
			//entity.IspisNaziv = (Convert.IsDBNull(reader["IspisNaziv"]))?string.Empty:(System.String)reader["IspisNaziv"];
			entity.IspisKolonaID = (System.Int32)reader["IspisKolonaID"];
			//entity.IspisKolonaID = (Convert.IsDBNull(reader["IspisKolonaID"]))?(int)0:(System.Int32)reader["IspisKolonaID"];
			entity.IspisKolonaNaziv = (System.String)reader["IspisKolonaNaziv"];
			//entity.IspisKolonaNaziv = (Convert.IsDBNull(reader["IspisKolonaNaziv"]))?string.Empty:(System.String)reader["IspisKolonaNaziv"];
			entity.IspisKolonaNaziv2 = reader.IsDBNull(reader.GetOrdinal("IspisKolonaNaziv2")) ? null : (System.String)reader["IspisKolonaNaziv2"];
			//entity.IspisKolonaNaziv2 = (Convert.IsDBNull(reader["IspisKolonaNaziv2"]))?string.Empty:(System.String)reader["IspisKolonaNaziv2"];
			entity.TipIspisaID = (System.Int32)reader["TipIspisaID"];
			//entity.TipIspisaID = (Convert.IsDBNull(reader["TipIspisaID"]))?(int)0:(System.Int32)reader["TipIspisaID"];
			entity.TipIspisaNaziv = (System.String)reader["TipIspisaNaziv"];
			//entity.TipIspisaNaziv = (Convert.IsDBNull(reader["TipIspisaNaziv"]))?string.Empty:(System.String)reader["TipIspisaNaziv"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwIspis"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwIspis"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwIspis entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IspisID = (Convert.IsDBNull(dataRow["IspisID"]))?(int)0:(System.Int32)dataRow["IspisID"];
			entity.IspisNaziv = (Convert.IsDBNull(dataRow["IspisNaziv"]))?string.Empty:(System.String)dataRow["IspisNaziv"];
			entity.IspisKolonaID = (Convert.IsDBNull(dataRow["IspisKolonaID"]))?(int)0:(System.Int32)dataRow["IspisKolonaID"];
			entity.IspisKolonaNaziv = (Convert.IsDBNull(dataRow["IspisKolonaNaziv"]))?string.Empty:(System.String)dataRow["IspisKolonaNaziv"];
			entity.IspisKolonaNaziv2 = (Convert.IsDBNull(dataRow["IspisKolonaNaziv2"]))?string.Empty:(System.String)dataRow["IspisKolonaNaziv2"];
			entity.TipIspisaID = (Convert.IsDBNull(dataRow["TipIspisaID"]))?(int)0:(System.Int32)dataRow["TipIspisaID"];
			entity.TipIspisaNaziv = (Convert.IsDBNull(dataRow["TipIspisaNaziv"]))?string.Empty:(System.String)dataRow["TipIspisaNaziv"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwIspisFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwIspis"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwIspisFilterBuilder : SqlFilterBuilder<VwIspisColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwIspisFilterBuilder class.
		/// </summary>
		public VwIspisFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwIspisFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwIspisFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwIspisFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwIspisFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwIspisFilterBuilder

	#region VwIspisParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwIspis"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwIspisParameterBuilder : ParameterizedSqlFilterBuilder<VwIspisColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwIspisParameterBuilder class.
		/// </summary>
		public VwIspisParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwIspisParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwIspisParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwIspisParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwIspisParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwIspisParameterBuilder
} // end namespace
